
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/08/2012 22:43:15
-- Generated from EDMX file: C:\Users\Hyllekilde\Documents\Visual Studio 2010\Projects\rentit03\rentit03_server\Database\RentItModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RENTIT03];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PermissionRole_Permission]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PermissionRole] DROP CONSTRAINT [FK_PermissionRole_Permission];
GO
IF OBJECT_ID(N'[dbo].[FK_PermissionRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PermissionRole] DROP CONSTRAINT [FK_PermissionRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleUser_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleUser] DROP CONSTRAINT [FK_RoleUser_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleUser_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleUser] DROP CONSTRAINT [FK_RoleUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaGenre_Media]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaGenre] DROP CONSTRAINT [FK_MediaGenre_Media];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaGenre_Genre]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaGenre] DROP CONSTRAINT [FK_MediaGenre_Genre];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaImage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ImageSet] DROP CONSTRAINT [FK_MediaImage];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaLanguage_Media]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaLanguage] DROP CONSTRAINT [FK_MediaLanguage_Media];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaLanguage_Language]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaLanguage] DROP CONSTRAINT [FK_MediaLanguage_Language];
GO
IF OBJECT_ID(N'[dbo].[FK_MediaComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommentSet] DROP CONSTRAINT [FK_MediaComment];
GO
IF OBJECT_ID(N'[dbo].[FK_UserComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommentSet] DROP CONSTRAINT [FK_UserComment];
GO
IF OBJECT_ID(N'[dbo].[FK_VersionMedia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VersionSet] DROP CONSTRAINT [FK_VersionMedia];
GO
IF OBJECT_ID(N'[dbo].[FK_PurchaseVersion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PurchaseSet] DROP CONSTRAINT [FK_PurchaseVersion];
GO
IF OBJECT_ID(N'[dbo].[FK_PurchaseUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PurchaseSet] DROP CONSTRAINT [FK_PurchaseUser];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRating1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RatingSet] DROP CONSTRAINT [FK_UserRating1];
GO
IF OBJECT_ID(N'[dbo].[FK_RatingMedia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RatingSet] DROP CONSTRAINT [FK_RatingMedia];
GO
IF OBJECT_ID(N'[dbo].[FK_Ebook_inherits_Media]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaSet_Ebook] DROP CONSTRAINT [FK_Ebook_inherits_Media];
GO
IF OBJECT_ID(N'[dbo].[FK_Movie_inherits_Media]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MediaSet_Movie] DROP CONSTRAINT [FK_Movie_inherits_Media];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[RoleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleSet];
GO
IF OBJECT_ID(N'[dbo].[PermissionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PermissionSet];
GO
IF OBJECT_ID(N'[dbo].[PurchaseSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PurchaseSet];
GO
IF OBJECT_ID(N'[dbo].[RatingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RatingSet];
GO
IF OBJECT_ID(N'[dbo].[VersionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VersionSet];
GO
IF OBJECT_ID(N'[dbo].[MediaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaSet];
GO
IF OBJECT_ID(N'[dbo].[GenreSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GenreSet];
GO
IF OBJECT_ID(N'[dbo].[LanguageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LanguageSet];
GO
IF OBJECT_ID(N'[dbo].[ImageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ImageSet];
GO
IF OBJECT_ID(N'[dbo].[CommentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommentSet];
GO
IF OBJECT_ID(N'[dbo].[MediaSet_Ebook]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaSet_Ebook];
GO
IF OBJECT_ID(N'[dbo].[MediaSet_Movie]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaSet_Movie];
GO
IF OBJECT_ID(N'[dbo].[PermissionRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PermissionRole];
GO
IF OBJECT_ID(N'[dbo].[RoleUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleUser];
GO
IF OBJECT_ID(N'[dbo].[MediaGenre]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaGenre];
GO
IF OBJECT_ID(N'[dbo].[MediaLanguage]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaLanguage];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Address] nvarchar(max)  NULL,
    [PhoneNumber] nvarchar(max)  NULL,
    [Credits] int  NOT NULL,
    [Created] datetime  NOT NULL,
    [Updated] datetime  NOT NULL
);
GO

-- Creating table 'RoleSet'
CREATE TABLE [dbo].[RoleSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PermissionSet'
CREATE TABLE [dbo].[PermissionSet] (
    [Id] int  NOT NULL,
    [Name] nvarchar(max)  NULL
);
GO

-- Creating table 'PurchaseSet'
CREATE TABLE [dbo].[PurchaseSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StartTime] datetime  NOT NULL,
    [EndTime] datetime  NULL,
    [VersionId] int  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'RatingSet'
CREATE TABLE [dbo].[RatingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Vote] int  NOT NULL,
    [Review] nvarchar(max)  NULL,
    [Subject] nvarchar(max)  NULL,
    [Created] datetime  NOT NULL,
    [Updated] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [Medium_Id] int  NOT NULL
);
GO

-- Creating table 'VersionSet'
CREATE TABLE [dbo].[VersionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Resolution] nvarchar(max)  NOT NULL,
    [Format] nvarchar(max)  NOT NULL,
    [Price] int  NOT NULL,
    [RentDays] int  NULL,
    [MediaId] int  NOT NULL
);
GO

-- Creating table 'MediaSet'
CREATE TABLE [dbo].[MediaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Year] int  NOT NULL,
    [CoverUrl] nvarchar(max)  NULL,
    [Description] nvarchar(max)  NULL,
    [Votes] int  NULL,
    [Rating] float  NOT NULL,
    [Updated] datetime  NOT NULL,
    [Released] datetime  NULL,
    [Created] datetime  NOT NULL
);
GO

-- Creating table 'GenreSet'
CREATE TABLE [dbo].[GenreSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [MediaType] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'LanguageSet'
CREATE TABLE [dbo].[LanguageSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ImageSet'
CREATE TABLE [dbo].[ImageSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Url] nvarchar(max)  NOT NULL,
    [MediaId] int  NOT NULL
);
GO

-- Creating table 'CommentSet'
CREATE TABLE [dbo].[CommentSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Text] nvarchar(max)  NOT NULL,
    [MediaId] int  NOT NULL,
    [Created] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [Updated] datetime  NOT NULL
);
GO

-- Creating table 'MediaSet_Ebook'
CREATE TABLE [dbo].[MediaSet_Ebook] (
    [ISBN10] nvarchar(max)  NULL,
    [ISBN13] nvarchar(max)  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'MediaSet_Movie'
CREATE TABLE [dbo].[MediaSet_Movie] (
    [ImdbId] nvarchar(max)  NULL,
    [ImdbUrl] nvarchar(max)  NULL,
    [Rated] nvarchar(max)  NULL,
    [Runtime] decimal(18,0)  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'PermissionRole'
CREATE TABLE [dbo].[PermissionRole] (
    [Permissions_Id] int  NOT NULL,
    [Roles_Id] int  NOT NULL
);
GO

-- Creating table 'RoleUser'
CREATE TABLE [dbo].[RoleUser] (
    [Roles_Id] int  NOT NULL,
    [Users_Id] int  NOT NULL
);
GO

-- Creating table 'MediaGenre'
CREATE TABLE [dbo].[MediaGenre] (
    [Media_Id] int  NOT NULL,
    [Genres_Id] int  NOT NULL
);
GO

-- Creating table 'MediaLanguage'
CREATE TABLE [dbo].[MediaLanguage] (
    [Media_Id] int  NOT NULL,
    [Languages_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RoleSet'
ALTER TABLE [dbo].[RoleSet]
ADD CONSTRAINT [PK_RoleSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PermissionSet'
ALTER TABLE [dbo].[PermissionSet]
ADD CONSTRAINT [PK_PermissionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PurchaseSet'
ALTER TABLE [dbo].[PurchaseSet]
ADD CONSTRAINT [PK_PurchaseSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [PK_RatingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VersionSet'
ALTER TABLE [dbo].[VersionSet]
ADD CONSTRAINT [PK_VersionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MediaSet'
ALTER TABLE [dbo].[MediaSet]
ADD CONSTRAINT [PK_MediaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'GenreSet'
ALTER TABLE [dbo].[GenreSet]
ADD CONSTRAINT [PK_GenreSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'LanguageSet'
ALTER TABLE [dbo].[LanguageSet]
ADD CONSTRAINT [PK_LanguageSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ImageSet'
ALTER TABLE [dbo].[ImageSet]
ADD CONSTRAINT [PK_ImageSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CommentSet'
ALTER TABLE [dbo].[CommentSet]
ADD CONSTRAINT [PK_CommentSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MediaSet_Ebook'
ALTER TABLE [dbo].[MediaSet_Ebook]
ADD CONSTRAINT [PK_MediaSet_Ebook]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MediaSet_Movie'
ALTER TABLE [dbo].[MediaSet_Movie]
ADD CONSTRAINT [PK_MediaSet_Movie]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Permissions_Id], [Roles_Id] in table 'PermissionRole'
ALTER TABLE [dbo].[PermissionRole]
ADD CONSTRAINT [PK_PermissionRole]
    PRIMARY KEY NONCLUSTERED ([Permissions_Id], [Roles_Id] ASC);
GO

-- Creating primary key on [Roles_Id], [Users_Id] in table 'RoleUser'
ALTER TABLE [dbo].[RoleUser]
ADD CONSTRAINT [PK_RoleUser]
    PRIMARY KEY NONCLUSTERED ([Roles_Id], [Users_Id] ASC);
GO

-- Creating primary key on [Media_Id], [Genres_Id] in table 'MediaGenre'
ALTER TABLE [dbo].[MediaGenre]
ADD CONSTRAINT [PK_MediaGenre]
    PRIMARY KEY NONCLUSTERED ([Media_Id], [Genres_Id] ASC);
GO

-- Creating primary key on [Media_Id], [Languages_Id] in table 'MediaLanguage'
ALTER TABLE [dbo].[MediaLanguage]
ADD CONSTRAINT [PK_MediaLanguage]
    PRIMARY KEY NONCLUSTERED ([Media_Id], [Languages_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Permissions_Id] in table 'PermissionRole'
ALTER TABLE [dbo].[PermissionRole]
ADD CONSTRAINT [FK_PermissionRole_Permission]
    FOREIGN KEY ([Permissions_Id])
    REFERENCES [dbo].[PermissionSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Roles_Id] in table 'PermissionRole'
ALTER TABLE [dbo].[PermissionRole]
ADD CONSTRAINT [FK_PermissionRole_Role]
    FOREIGN KEY ([Roles_Id])
    REFERENCES [dbo].[RoleSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PermissionRole_Role'
CREATE INDEX [IX_FK_PermissionRole_Role]
ON [dbo].[PermissionRole]
    ([Roles_Id]);
GO

-- Creating foreign key on [Roles_Id] in table 'RoleUser'
ALTER TABLE [dbo].[RoleUser]
ADD CONSTRAINT [FK_RoleUser_Role]
    FOREIGN KEY ([Roles_Id])
    REFERENCES [dbo].[RoleSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Users_Id] in table 'RoleUser'
ALTER TABLE [dbo].[RoleUser]
ADD CONSTRAINT [FK_RoleUser_User]
    FOREIGN KEY ([Users_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleUser_User'
CREATE INDEX [IX_FK_RoleUser_User]
ON [dbo].[RoleUser]
    ([Users_Id]);
GO

-- Creating foreign key on [Media_Id] in table 'MediaGenre'
ALTER TABLE [dbo].[MediaGenre]
ADD CONSTRAINT [FK_MediaGenre_Media]
    FOREIGN KEY ([Media_Id])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Genres_Id] in table 'MediaGenre'
ALTER TABLE [dbo].[MediaGenre]
ADD CONSTRAINT [FK_MediaGenre_Genre]
    FOREIGN KEY ([Genres_Id])
    REFERENCES [dbo].[GenreSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MediaGenre_Genre'
CREATE INDEX [IX_FK_MediaGenre_Genre]
ON [dbo].[MediaGenre]
    ([Genres_Id]);
GO

-- Creating foreign key on [MediaId] in table 'ImageSet'
ALTER TABLE [dbo].[ImageSet]
ADD CONSTRAINT [FK_MediaImage]
    FOREIGN KEY ([MediaId])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MediaImage'
CREATE INDEX [IX_FK_MediaImage]
ON [dbo].[ImageSet]
    ([MediaId]);
GO

-- Creating foreign key on [Media_Id] in table 'MediaLanguage'
ALTER TABLE [dbo].[MediaLanguage]
ADD CONSTRAINT [FK_MediaLanguage_Media]
    FOREIGN KEY ([Media_Id])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Languages_Id] in table 'MediaLanguage'
ALTER TABLE [dbo].[MediaLanguage]
ADD CONSTRAINT [FK_MediaLanguage_Language]
    FOREIGN KEY ([Languages_Id])
    REFERENCES [dbo].[LanguageSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MediaLanguage_Language'
CREATE INDEX [IX_FK_MediaLanguage_Language]
ON [dbo].[MediaLanguage]
    ([Languages_Id]);
GO

-- Creating foreign key on [MediaId] in table 'CommentSet'
ALTER TABLE [dbo].[CommentSet]
ADD CONSTRAINT [FK_MediaComment]
    FOREIGN KEY ([MediaId])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MediaComment'
CREATE INDEX [IX_FK_MediaComment]
ON [dbo].[CommentSet]
    ([MediaId]);
GO

-- Creating foreign key on [UserId] in table 'CommentSet'
ALTER TABLE [dbo].[CommentSet]
ADD CONSTRAINT [FK_UserComment]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserComment'
CREATE INDEX [IX_FK_UserComment]
ON [dbo].[CommentSet]
    ([UserId]);
GO

-- Creating foreign key on [MediaId] in table 'VersionSet'
ALTER TABLE [dbo].[VersionSet]
ADD CONSTRAINT [FK_VersionMedia]
    FOREIGN KEY ([MediaId])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VersionMedia'
CREATE INDEX [IX_FK_VersionMedia]
ON [dbo].[VersionSet]
    ([MediaId]);
GO

-- Creating foreign key on [VersionId] in table 'PurchaseSet'
ALTER TABLE [dbo].[PurchaseSet]
ADD CONSTRAINT [FK_PurchaseVersion]
    FOREIGN KEY ([VersionId])
    REFERENCES [dbo].[VersionSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PurchaseVersion'
CREATE INDEX [IX_FK_PurchaseVersion]
ON [dbo].[PurchaseSet]
    ([VersionId]);
GO

-- Creating foreign key on [UserId] in table 'PurchaseSet'
ALTER TABLE [dbo].[PurchaseSet]
ADD CONSTRAINT [FK_PurchaseUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PurchaseUser'
CREATE INDEX [IX_FK_PurchaseUser]
ON [dbo].[PurchaseSet]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [FK_UserRating1]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRating1'
CREATE INDEX [IX_FK_UserRating1]
ON [dbo].[RatingSet]
    ([UserId]);
GO

-- Creating foreign key on [Medium_Id] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [FK_RatingMedia]
    FOREIGN KEY ([Medium_Id])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RatingMedia'
CREATE INDEX [IX_FK_RatingMedia]
ON [dbo].[RatingSet]
    ([Medium_Id]);
GO

-- Creating foreign key on [Id] in table 'MediaSet_Ebook'
ALTER TABLE [dbo].[MediaSet_Ebook]
ADD CONSTRAINT [FK_Ebook_inherits_Media]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'MediaSet_Movie'
ALTER TABLE [dbo].[MediaSet_Movie]
ADD CONSTRAINT [FK_Movie_inherits_Media]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[MediaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------